package com.emergency.db.controller.work;

import com.emergency.base.domain.Army;
import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.staff.Staff;
import com.emergency.db.service.work.ArmyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/army")
@CrossOrigin
public class ArmyController {
    @Autowired
    private ArmyService armyService;

    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody Army army) {
        Long id = armyService.save(army);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //保存全部
    @RequestMapping(value = "/save/all", method = RequestMethod.POST)
    public Result saveAll(@RequestBody List<Army> armyList) {
        armyService.saveAll(armyList);
        return new Result(true, StatusCode.OK, "保存成功");
    }

    //查询全部
    @RequestMapping(value = "/search/all", method = RequestMethod.POST)
    public Result findAll() {
        List<Army> armyList = armyService.findAll();
        return new Result(true, StatusCode.OK, "查询成功", armyList);
    }

    //查询单项
    @RequestMapping(value = "/search/{id}", method = RequestMethod.POST)
    public Result findById(@PathVariable("id") Long id) {
        Army army = armyService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", army);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result delete(@PathVariable Long id) {
        Long del = armyService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功", del);
    }

    //分页
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<Army> pageList = armyService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
